import express from 'express';
import jwt from 'jsonwebtoken';
// import { secretKey } from './config';
const secretKey = 'your_secret_key';

const dashboard = express.Router();

dashboard.get('/reportData', (req, res) => {
  // 获取请求头中的 token
  const token = req.headers['authorization'];
  if (!token) {
    return res.json({
      success: false,
      code: 401,
      message: '未登录',
      data: null
    });
  }
  try {
    // 验证 token
    const userInfo = jwt.verify(token, secretKey);
    res.json({
      success: true,
      code: 100,
      message: '获取用户信息成功',
      data: {
        "driverCount": 278600,
        "totalMoney": 3984200,
        "orderCount": 1306000,
        "cityNum": 80
      }
    });
  } catch (error) {
    res.json({
      success: false,
      code: 401,
      message: '登录失效',
      data: null
    });
  }

});
dashboard.get('/lineData', (req, res) => {
  // 获取请求头中的 token
  const token = req.headers['authorization'];
  if (!token) {
    return res.json({
      success: false,
      code: 401,
      message: '未登录',
      data: null
    });
  }
  try {
    // 验证 token
    const userInfo = jwt.verify(token, secretKey);
    res.json({
      success: true,
      code: 100,
      message: '成功',
      data: {
        dates: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        orderData: [1200, 1322, 901, 934, 1290, 1330, 1320, 1200, 1322, 901, 934, 1290],
        waterData: [2220, 2182, 901, 934, 1290, 1330, 1320, 1200, 1322, 901, 934, 1290],

      }
    });
  } catch (error) {
    res.json({
      success: false,
      code: 401,
      message: '登录失效',
      data: null
    });
  }

});
dashboard.get('/pieData', (req, res) => {
  // 获取请求头中的 token
  const token = req.headers['authorization'];
  if (!token) {
    return res.json({
      success: false,
      code: 401,
      message: '未登录',
      data: null
    });
  }
  try {
    // 验证 token
    const userInfo = jwt.verify(token, secretKey);
    res.json({
      success: true,
      code: 100,
      message: '成功',
      data: [
        { value: 1048, name: '搜索' },
        { value: 735, name: '直接' },
        { value: 580, name: '邮箱' },
        { value: 484, name: '广告' },
        { value: 300, name: '视频' }
      ]
    });
  } catch (error) {
    res.json({
      success: false,
      code: 401,
      message: '登录失效',
      data: null
    });
  }

});
dashboard.get('/radarData', (req, res) => {
  // 获取请求头中的 token
  const token = req.headers['authorization'];
  if (!token) {
    return res.json({
      success: false,
      code: 401,
      message: '未登录',
      data: null
    });
  }
  try {
    // 验证 token
    const userInfo = jwt.verify(token, secretKey);
    res.json({
      success: true,
      code: 100,
      message: '成功',
      data: {
        indicator: [
          { name: '销售量', max: 6500 },
          { name: '管理', max: 16000 },
          { name: '信息技术部', max: 30000 },
          { name: '顾客支持', max: 38000 },
          { name: '开发', max: 52000 },
          { name: '市场', max: 25000 }
        ],
        // 预算
        budget: [4300, 10000, 28000, 35000, 50000, 19000],
        // 实际开销
        actual: [5000, 14000, 28000, 31000, 42000, 21000]
      }
    });
  } catch (error) {
    res.json({
      success: false,
      code: 401,
      message: '登录失效',
      data: null
    });
  }

});
export default dashboard;